# 28_utas2012_subjective_position.R
# Purpose: Ideological Extremism and Political Participation in Japan
# Created: 2021-7-19 Taka-aki Asano
# Last Modified: 2022-1-4

# package
require("haven")
require("dplyr")
require("tidyr")
require("ggplot2")
quartzFonts(HiraKaku = quartzFont(rep('Hiragino Kaku Gothic Pro W3', 4)))
theme_set(theme_classic(base_size = 12, base_family = 'HiraKaku'))


# 2012
## merge
UTAS2012_Ideology <- voter2012[,c("ID", "Q010100", "Q014100", "Q014300", "Q014200", "Q013700", "Ideology", "Q013300")]
UTAS2012_Ideology <- as.data.frame(UTAS2012_Ideology)
UTAS2012_Ideology$Q013300[UTAS2012_Ideology$Q013300 == 99] <- NA

## plot
Ideology_Compare <- ggplot(
  UTAS2012_Ideology[!is.na(UTAS2012_Ideology$Q013300),], 
  aes(x = as.factor(Q013300), y = Ideology)) + 
  geom_boxplot() + ylim(-4.0, 4.0) + 
  labs(x = expression(Left  %<-%  "Subjective Ideological Position" %->% Right), 
       y = expression(Left  %<-%  "Objective Ideological Position" %->% Right), 
       title = "(a) All Respondents") + 
  theme(plot.title = element_text(hjust = 0.5))
plot(Ideology_Compare)

Ideology_Compare_Young <- ggplot(
  UTAS2012_Ideology[!is.na(UTAS2012_Ideology$Q013300) & UTAS2012_Ideology$Q014200 <= 2,], 
  aes(x = as.factor(Q013300), y = Ideology)) + 
  geom_boxplot() + ylim(-4.0, 4.0) + 
  labs(x = expression(Left  %<-%  "Subjective Ideological Position" %->% Right), 
       y = expression(Left  %<-%  "Objective Ideological Position" %->% Right), 
       title = "(b) Respondents Aged 39 or Younger") + 
  theme(plot.title = element_text(hjust = 0.5))
plot(Ideology_Compare_Young)

Ideology_Compare_Old <- ggplot(
  UTAS2012_Ideology[!is.na(UTAS2012_Ideology$Q013300) & UTAS2012_Ideology$Q014200 >= 5,], 
  aes(x = as.factor(Q013300), y = Ideology)) + 
  geom_boxplot() + ylim(-4.0, 4.0) + 
  labs(x = expression(Left  %<-%  "Subjective Ideological Position" %->% Right), 
       y = expression(Left  %<-%  "Objective Ideological Position" %->% Right), 
       title = "(c) Respondents Aged 60 or Older") + 
  theme(plot.title = element_text(hjust = 0.5))
plot(Ideology_Compare_Old)

## recode
UTAS2012_Ideology$Vote <- NA
UTAS2012_Ideology$Vote[UTAS2012_Ideology$Q010100 == 2] <- 1
UTAS2012_Ideology$Vote[UTAS2012_Ideology$Q010100 == 1] <- 0
UTAS2012_Ideology$Q013300_Strong <- abs(UTAS2012_Ideology$Q013300 - 5)
UTAS2012_Ideology$Q013700[UTAS2012_Ideology$Q013700 == 99] <- NA
UTAS2012_Ideology$Support <- ifelse(UTAS2012_Ideology$Q013700 == 14, 0, 1)
UTAS2012_Ideology$Female <- ifelse(UTAS2012_Ideology$Q014100 == 2, 1, 0)
UTAS2012_Ideology$Q014300[UTAS2012_Ideology$Q014300 == 99] <- NA
UTAS2012_Ideology$College <- ifelse(UTAS2012_Ideology$Q014300 %in% c(5, 6), 1, 0)
UTAS2012_Ideology$Age <- UTAS2012_Ideology$Q014200

## regression
vote2012 <- glm(
  Vote ~ Q013300 + Q013300_Strong + Support + Female + College + Age, 
  data = UTAS2012_Ideology, family = binomial(link = "logit")
)
summary(vote2012)
